<!--
  - Copyright (C) 2018-2019
  - All rights reserved, Designed By www.joolun.com
  - 注意：
  - 本软件为www.joolun.com开发研制，项目使用请保留此说明
-->
<template>
  <div class="app-container">
        <el-card>
          <el-row style="margin-bottom:10px">
            <span style="margin-right: 10px;">请选择比赛</span>
             <el-select @change="checkChange" v-model="competitionValue" placeholder="请选择">
              <el-option v-for="item in selectCompetitionValue" :key="item.id" :label="item.competitionName" :value="item.id">
              </el-option>
            </el-select>
          </el-row>
            <el-table height="490px" border stripe :data="tableData" style="width: 100%">
                <el-table-column align="center" label="公众号openId" prop="wxGzhUser.openidGzh"></el-table-column>
                <el-table-column align="center" label="选手姓名" prop="name"></el-table-column>
                 <el-table-column align="center" label="主播名" prop="age"></el-table-column>
                <el-table-column align="center" label="选手手机号" prop="telephone"></el-table-column>
                <el-table-column align="center" label="行业过往经历" prop="industryExperience"></el-table-column>
                <el-table-column align="center" label="作品名称" prop="title">

                </el-table-column>
                 <el-table-column align="center" label="比赛宣言视频地址" prop="declaration"></el-table-column>
                <el-table-column align="center" width="350px" label="参赛作品" prop="work">
                  <template slot-scope="scope">
						        <!-- <div class="play-button">
						            <img src="../../../assets/images/home_icon_play.png" v-show="playshow" @click="play(scope.$index)"/>
						            <img src="../../../assets/images/home_icon_stop.png" v-show="stipshow" @click="stop(scope.$index)"/>
						        </div> -->
				            <audio controls :src="scope.row.work" >
				            </audio>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="选手赛道" prop="racetrack">
                  <template slot-scope="scope" >
                      <el-tag hit type="success" >{{scope.row.registrationRacetrack.raceTrackName}}</el-tag>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="操作" width="200">
                    <template slot-scope="scope" >

                        <div v-if="scope.row.submitCompleted == 0">
                            <el-button size="mini" type="warning" disabled>未上传作品</el-button>
                        </div>

                        <div v-else>
                          <el-button size="mini" v-if="scope.row.participateStatus==0" type="warning" disabled>未支付</el-button>
                          <el-button size="mini" v-else-if="scope.row.participateStatus==1" type="primary" @click="formHandleEditBtn(scope.$index, scope.row)">确定海选</el-button>
                          <el-button size="mini" v-else-if="scope.row.participateStatus==2" type="success" disabled>进入初赛</el-button>
                          <el-button size="mini" v-else-if="scope.row.participateStatus==3" type="success" disabled>进入复赛</el-button>
                          <el-button size="mini" v-else-if="scope.row.participateStatus==4" type="success" disabled>进入决赛</el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination :page-size="tablePage.size" @current-change="currentChange" hide-on-single-page background layout="prev, pager, next" :total="tablePage.total" ></el-pagination>
        </el-card>
        <!-- 弹出框部分 -->
        <el-dialog :title="formTitle" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
          <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="赛道名称" prop="raceTrackName">
              <el-input v-model="ruleForm.raceTrackName"></el-input>
            </el-form-item>
            <el-form-item label="赛道信息" prop="raceTrackDescribe">
              <el-tag :key="tag" v-for="tag in ruleForm.raceTrackDescribe" closable :disable-transitions="false" @close="handleTagClose(tag)"> {{tag}}</el-tag>
              <el-input class="input-new-tag" v-if="inputVisible" v-model="inputValue" ref="saveTagInput" size="small" @keyup.enter.native="handleInputConfirm" @blur="handleInputConfirm">
              </el-input>
              <el-button v-else class="button-new-tag" size="small" @click="showInput">+ New Tag</el-button>
            </el-form-item>
            <el-form-item>
              <el-button v-loading.fullscreen.lock="fullscreenLoading" type="primary" @click="submitForm('ruleForm')">{{ruleFormSubmitType}}</el-button>
            </el-form-item>
          </el-form>
        </el-dialog>
  </div>
</template>
<script>
  import {checkPermi, checkRole} from "@/utils/permission"
  import {getPage,tableDataDelete, tableInsert,tableUpdate,getAllCompetitions,confirmAudition } from '@/api/contest/signUp'
  import {tableOption} from '@/const/crud/mall/goodscategory'

  export default {
    components: {},
    name: 'signup',
    data() {
      return {
        competitionValue:"",
        //赛事信息
        selectCompetitionValue:[],
        //playshow:true, //播放的图片
			  //stipshow:false, //暂停的图片
        selectContest:"",
        formTitle:"添加赛道信息",
        fullscreenLoading:false,
        ruleFormSubmitType:"确定添加",
        ruleForm: {
          raceTrackName: '',
          raceTrackDescribe:[]
        },
        rules: {
          raceTrackName: [
            { required: true, message: '请输入活动名称', trigger: 'blur' },
          ],
          raceTrackDescribe: [
            { required: true, message: '至少输入一个赛道信息', trigger: 'blur' },
          ]
        },
        tablePage:{
          page:1,
          size:10,
          total:0
        },
        tableData: [],
        tableLoading: false,
        tableOption: tableOption,
        dialogVisible: false,
        inputVisible: false,
        inputValue: ''
      }
    },
    async created() {
      //获取赛事
      await this.getAllCompetitions()
      this.getRegistrationRaceTrackList()
    },
    mounted: function () {
    },
    computed: {
    },
    methods: {
      //分页查询数据
      currentChange(e){
          this.tablePage.page = e
          this.getRegistrationRaceTrackList()
      },
      //修改数据
      submitForm(formName){
        this.$refs[formName].validate((valid) => {
          if (valid) {
            if(this.ruleFormSubmitType=="确定添加"){
              this.registrationInsert(this.ruleForm)
            }
            if(this.ruleFormSubmitType=="确定修改"){
              this.registrationUpdate(this.ruleForm)
            }
          } else {
            this.$notify({title: '警告',message: '请填写正确信息',type: 'warning'});
            return false;
          }
        });
      },
      //添加赛道信息
      async registrationInsert(data){
        this.fullscreenLoading=true
        const res = await tableInsert(data)
        if(res.code == 200&&res.data){
          this.$message({type: 'success',message: '添加成功'}); 
          this.fullscreenLoading = false
          this.dialogVisible = false
          this.refreshChange()
        }
      },
      //修改赛道信息
      async registrationUpdate(data){
        const res = await tableUpdate(data)
        if(res.code == 200&&res.data){
          this.$message({type: 'success',message: '修改成功'}); 
          this.fullscreenLoading = false
          this.dialogVisible = false
          this.refreshChange()
        }
      },
      //分页查询
      async getRegistrationRaceTrackList(){
          if(this.competitionValue == ""){
             this.$message({
                message: '请先选择比赛',
                type: 'warning'
             });
            return
          }
          const res = await getPage(this.tablePage.page,this.tablePage.size,this.competitionValue)
          if(res.code == 200){
            const result = res.data;
            //设置数据总数
            this.tablePage.total = result.total
            this.tableData = result.records
            console.log(this.tableData)
          }else{
            this.$notify({title: '警告',message: '获取赛道列表失败请尝试刷新重新获取',type: 'warning'});
        }
      },
      // handleDelete(e){
      //   this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {confirmButtonText: '确定',cancelButtonText: '取消',type: 'warning'
      //   }).then(() => {
      //     this.tableDataDelete(this.tableData[e].id);
      //   }).catch(() => {
      //     this.$message({type: 'info',message: '已取消删除'}); 
      //   })     
      // },
      /**
       * 刷新回调
       */
      async tableDataDelete(id){
        const res = await tableDataDelete(id)
        if(res.code == 200 && res.data){
          this.$notify({title: '成功',message: '删除成功',type: 'success'});
          this.refreshChange()
        }else{
          this.$notify.error({title: '错误',message: '删除失败',});
        }
      },
      refreshChange() {
        this.getRegistrationRaceTrackList()
      },
      handleClose(done) {
        this.$confirm('确认关闭？').then(_ => {done();}).catch(_ => {});
      },
      //赛道描述单元添加
      showInput() {
        this.inputVisible = true;
        this.$nextTick(_ => {this.$refs.saveTagInput.$refs.input.focus();});
      },
       handleInputConfirm() {
        let inputValue = this.inputValue;
        if (inputValue) {
          this.ruleForm.raceTrackDescribe.push(inputValue);
        }
        this.inputVisible = false;
        this.inputValue = '';
      },
      //赛道描述单元删除
      handleTagClose(tag){
        this.ruleForm.raceTrackDescribe.splice(this.ruleForm.raceTrackDescribe.indexOf(tag), 1);
      },
      //修改赛道信息btn
      formHandleEditBtn(key,row){
         this.$confirm('将此选手加入初赛?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(async() => {
          const res = await confirmAudition(row)
          if(res.code == 200){
          this.$message({
            type: 'success',
            message: '加入还初赛成功!'
          });
          this.getRegistrationRaceTrackList()
          }else{
             this.$message({
            type: 'errir',
            message: '加入还初赛失败!'
          });
          }
         
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      //获取全部赛事
      async getAllCompetitions(){
        console.log("获取全部赛事+带上赛事的id号")
        const res = await getAllCompetitions()
        if(res.code == 200){
            this.selectCompetitionValue = res.data
          console.log(this.selectCompetitionValue)
        }else{
          this.$message.error('获取赛事信息失败');
        }
      },
      checkChange(){
        console.log(this.competitionValue)
        this.getRegistrationRaceTrackList()
        //选中之后开始获取报名表
      }
    }
  }
</script>

<style lang="scss" scoped>
.el-tag{
  margin-bottom: 5px;
  margin-left: 5px;
}
.el-pagination{
  text-align: center;
  margin-top: 40px;
}
.el-tag + .el-tag {
    margin-left: 10px;
  }
  .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
  }
// .play-button{
// 					display: flex;
// 					justify-content: center;
// 					image{
// 						width: 100px;
// 						height: 100px;
// 					}
// 				}
</style>
